package org.zhadoop.stream.cql.semanticanalyzer.parser.context;

import java.util.List;

import org.zhadoop.stream.cql.DriverContext;
import org.zhadoop.stream.cql.exception.CQLException;
import org.zhadoop.stream.cql.exception.SemanticAnalyzerException;
import org.zhadoop.stream.cql.hooks.SemanticAnalyzeHook;
import org.zhadoop.stream.cql.semanticanalyzer.SemanticAnalyzer;
import org.zhadoop.stream.cql.semanticanalyzer.parsecontextwalker.ParseContextWalker;
import org.zhadoop.stream.cql.tasks.Task;

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;

/**
 * JoinSource语法解析
 * @author zwd
 *
 */
public class JoinSourceContext extends ParseContext{
	
	private List<JoinRigthBodyContext> joinRightBody;
	
	/**
	 * 如果存在Join，该字段就是最左边的Join流
	 * 如果不存在Join，该字段就是唯一的数据源流
	 */
	 private FromSourceContext leftStream;

	 public JoinSourceContext() {
		 joinRightBody = Lists.newArrayList();
	}
	 
	@Override
	public String toString() {
		return leftStream.toString() + Joiner.on(" ").join(joinRightBody);
	}
	
	public FromSourceContext getLeftStream() {
		return leftStream;
	}

	public void setLeftStream(FromSourceContext leftStream) {
		this.leftStream = leftStream;
	}


	public List<JoinRigthBodyContext> getJoinRightBody() {
		return joinRightBody;
	}

	public void setJoinRightBody(List<JoinRigthBodyContext> joinRightBody) {
		this.joinRightBody = joinRightBody;
	}

	@Override
	public Task createTask(DriverContext driverContext, List<SemanticAnalyzeHook> analyzeHooks) throws CQLException {
		return null;
	}

	@Override
	public SemanticAnalyzer createAnalyzer() throws SemanticAnalyzerException {
		return null;
	}



	@Override
	protected void walkChild(ParseContextWalker walker) {
		walkExpression(walker, leftStream);
		for(JoinRigthBodyContext right : joinRightBody){
			walkExpression(walker, right);
		}
	}
}
